package com.fileServer.client;

import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.model.CannedAccessControlList;
import com.amazonaws.services.s3.model.PutObjectResult;
import com.amazonaws.services.s3.model.S3Object;
import com.fileServer.config.OssProperties;
import com.fileServer.util.FileUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.io.InputStream;

/**
 * @author 大忽悠
 * @create 2023/2/27 20:27
 */
@Component
@RequiredArgsConstructor
public class LocalOssClient implements OssClient{
    private final OssProperties ossProperties;

    @Override
    public void createBucket(String bucketName) {
        FileUtil.createDir(ossProperties.getRootPath(),bucketName);
    }

    /**
     * 将文件上传到本地
     */
    @Override
    public PutObjectResult putObject(String bucketName, String objectName, InputStream stream, long size, String contextType) throws IOException {
        String filePath = FileUtil.pathMerge(ossProperties.getRootPath(), bucketName, objectName);
        FileUtil.transFileTo(stream,filePath);
        return null;
    }

    @Override
    public void deleteObject(String bucketName, String objectName) {
        String filePath = FileUtil.pathMerge(ossProperties.getRootPath(), bucketName, objectName);
        FileUtil.deleteFile(filePath);
    }


    @Override
    public void createBucket(String bucketName, CannedAccessControlList bucketAccess) {}
    @Override
    public void deleteBucket(String bucketName){}
    @Override
    public String getObjectURL(String bucketName, String objectName) {return null;}
    @Override
    public S3Object getObjectInfo(String bucketName, String objectName) {return null;}
    @Override
    public AmazonS3 getS3Client() {return null;}
}
